const state = {
  roletree:[]
}
const mutations ={
    SET_ROLETREE(state:any,data:any){
        state.roletree.push(...data)
        // console.log(state.roletree,data,'vuex树状图');
    }
}

// id: 3,
// label: "权限列表",
// children
interface tree {authName:string,id:number,children:[]}
const actions = {
    SET_ROLETREE({commit}:any,data:any){
     const fn=(data:any)=>{
        // console.log(data,'初始值');
        const newData:any = data.map(({authName,id,children}:tree)=>{
        //    console.log(children,'children');
           if(children){
            return {
                id:id,
                label:authName,
                children:fn(children)
            }
           }else{
            return {
                id:id,
                label:authName,
            }
           }
        })
        return newData
     }
    const newData = fn(data)
    // console.log( newData,'总信息');
    newData.length===state.roletree.length?false:commit('SET_ROLETREE',newData)
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
  }
 